home *** CD-ROM | disk | FTP | other *** search
/ MacHome 1999 February/March / MacHome CD (February and March 1999).iso / Edutainment / INFOHIGHWAYDEMOS / demo / ACCUEIL.DCR / 00164.ls < prev    next >
Encoding:
Text File  |  1999-12-02  |  6.5 KB  |  253 lines

  1. on AnimationSystemInitialize
  2.   global ListAnim, ListRolls, ListSounds
  3.   set ListRolls to []
  4.   set ListAnim to []
  5. end
  6.  
  7. on soundSystemInitialize
  8.   global vol, ListSounds, BTNSOUNDCHANNEL
  9.   set the soundLevel to 4
  10.   set BTNSOUNDCHANNEL to 4
  11.   set ListSounds to []
  12.   set vol to 255
  13. end
  14.  
  15. on NonThreadedAnimSeq spriteNum, ImageList, delay, Unpuppet
  16.   set nbImages to count(ImageList)
  17.   set i to 1
  18.   puppetSprite(spriteNum, 1)
  19.   repeat while i <= nbImages
  20.     set the member of sprite spriteNum to member getAt(ImageList, i)
  21.     updateStage()
  22.     set i to i + 1
  23.     wait(delay)
  24.   end repeat
  25.   puppetSprite(spriteNum, not Unpuppet)
  26. end
  27.  
  28. on startAnim spriteNum, rootName, listFrames, delay, loop, Unpuppet
  29.   global ListAnim
  30.   append(ListAnim, [spriteNum, rootName, listFrames, delay, 0, the ticks, 0, loop, Unpuppet])
  31. end
  32.  
  33. on stopAnim spriteNum
  34.   global ListAnim
  35.   set check to checkAnim(spriteNum)
  36.   if check > 0 then
  37.     if getAt(getAt(ListAnim, check), 9) = 1 then
  38.       puppetSprite(spriteNum, 0)
  39.     end if
  40.     deleteAt(ListAnim, check)
  41.   end if
  42. end
  43.  
  44. on checkAnim spriteNum
  45.   global ListAnim
  46.   set i to 1
  47.   set nbAnim to count(ListAnim)
  48.   repeat while i <= nbAnim
  49.     if spriteNum = getAt(getAt(ListAnim, i), 1) then
  50.       return i
  51.     end if
  52.     set i to i + 1
  53.   end repeat
  54.   return 0
  55. end
  56.  
  57. on mixDownAnim
  58.   global ListAnim
  59.   set i to 1
  60.   repeat while i <= count(ListAnim)
  61.     set spriteNum to getAt(getAt(ListAnim, i), 1)
  62.     set listFrames to getAt(getAt(ListAnim, i), 3)
  63.     set nbframes to count(listFrames)
  64.     set delay to getAt(getAt(ListAnim, i), 4)
  65.     set lastFrame to getAt(getAt(ListAnim, i), 5)
  66.     set lastTick to getAt(getAt(ListAnim, i), 6)
  67.     set nbTimes to getAt(getAt(ListAnim, i), 7)
  68.     set loop to getAt(getAt(ListAnim, i), 8)
  69.     set Unpuppet to getAt(getAt(ListAnim, i), 9)
  70.     puppetSprite(spriteNum, 1)
  71.     if ((the ticks - lastTick) >= delay) or (lastFrame = 0) then
  72.       if loop = 0 then
  73.         stopAnim(spriteNum)
  74.       else
  75.         if loop < 0 then
  76.           if lastFrame = nbframes then
  77.             set lastFrame to 1
  78.           else
  79.             set lastFrame to lastFrame + 1
  80.           end if
  81.           set the member of sprite spriteNum to member getAt(listFrames, lastFrame)
  82.           updateStage()
  83.           setAt(getAt(ListAnim, i), 5, lastFrame)
  84.           setAt(getAt(ListAnim, i), 6, the ticks)
  85.           setAt(getAt(ListAnim, i), 7, nbTimes)
  86.         else
  87.           if lastFrame = nbframes then
  88.             set lastFrame to 1
  89.             set nbTimes to nbTimes + 1
  90.           else
  91.             set lastFrame to lastFrame + 1
  92.           end if
  93.           if nbTimes = loop then
  94.             stopAnim(spriteNum)
  95.           else
  96.             set the member of sprite spriteNum to member getAt(listFrames, lastFrame)
  97.             updateStage()
  98.             setAt(getAt(ListAnim, i), 5, lastFrame)
  99.             setAt(getAt(ListAnim, i), 6, the ticks)
  100.             setAt(getAt(ListAnim, i), 7, nbTimes)
  101.           end if
  102.         end if
  103.       end if
  104.     end if
  105.     set i to i + 1
  106.   end repeat
  107. end
  108.  
  109. on forcePlaySound snd, chnl
  110.   if soundBusy(chnl) then
  111.     sound stop chnl
  112.   end if
  113.   puppetSound(chnl, snd)
  114. end
  115.  
  116. on playsound snd, chnl, vol
  117.   if not soundBusy(chnl) then
  118.     if not voidp(vol) then
  119.       set the volume of sound chnl to vol
  120.     end if
  121.     puppetSound(chnl, snd)
  122.     updateStage()
  123.     return 1
  124.   end if
  125.   return 0
  126. end
  127.  
  128. on HardPlaySound snd, chnl
  129.   if not soundBusy(chnl) then
  130.     puppetSound(chnl, snd)
  131.     updateStage()
  132.     repeat while soundBusy(chnl)
  133.     end repeat
  134.     return 1
  135.   end if
  136.   return 0
  137. end
  138.  
  139. on checkSound snd, chnl
  140.   global ListSounds
  141.   set i to 1
  142.   set nbsound to count(ListSounds)
  143.   repeat while i <= nbsound
  144.     if (snd = getAt(getAt(ListSounds, i), 1)) and (chnl = getAt(getAt(ListSounds, i), 2)) then
  145.       return i
  146.     end if
  147.     set i to i + 1
  148.   end repeat
  149.   return 0
  150. end
  151.  
  152. on startSoundSequence snd, chnl, vol, delay, loop
  153.   global ListSounds
  154.   if checkSound(snd, chnl) = 0 then
  155.     append(ListSounds, [snd, chnl, vol, delay, the ticks, 0, loop])
  156.   end if
  157. end
  158.  
  159. on stopSoundSequence snd, chnl
  160.   global ListSounds
  161.   set check to checkSound(snd, chnl)
  162.   if check > 0 then
  163.     deleteAt(ListSounds, check)
  164.   end if
  165. end
  166.  
  167. on mixDownSound
  168.   global ListSounds
  169.   set i to 1
  170.   repeat while i <= count(ListSounds)
  171.     set sound to getAt(getAt(ListSounds, i), 1)
  172.     set channel to getAt(getAt(ListSounds, i), 2)
  173.     set vol to getAt(getAt(ListSounds, i), 3)
  174.     set delay to getAt(getAt(ListSounds, i), 4)
  175.     set lastTick to getAt(getAt(ListSounds, i), 5)
  176.     set nbTimesPlayed to getAt(getAt(ListSounds, i), 6)
  177.     set maxTimesToPlay to getAt(getAt(ListSounds, i), 7)
  178.     if nbTimesPlayed = maxTimesToPlay then
  179.       stopSoundSequence(sound, channel)
  180.     else
  181.       if ((the ticks - lastTick) >= delay) or (nbTimesPlayed = 0) then
  182.         forcePlaySound(sound, channel)
  183.         set nbTimesPlayed to nbTimesPlayed + 1
  184.         setAt(getAt(ListSounds, i), 5, the ticks)
  185.         setAt(getAt(ListSounds, i), 6, nbTimesPlayed)
  186.       end if
  187.     end if
  188.     set i to i + 1
  189.   end repeat
  190. end
  191.  
  192. on checkRoll spriteNum
  193.   global ListRolls
  194.   set i to 1
  195.   set nbRolls to count(ListRolls)
  196.   repeat while i <= nbRolls
  197.     set trigger to getAt(getAt(getAt(ListRolls, i), 1), 1)
  198.     if spriteNum = getAt(trigger, 1) then
  199.       return i
  200.     end if
  201.     set i to i + 1
  202.   end repeat
  203.   return 0
  204. end
  205.  
  206. on rollOverBtn rolls, snd, chnl, vol, sndDelay, loop
  207.   global ListRolls
  208.   set trigger to getAt(rolls, 1)
  209.   set triggerSprNum to getAt(trigger, 1)
  210.   if checkRoll(triggerSprNum) = 0 then
  211.     if not voidp(snd) then
  212.       startSoundSequence(snd, chnl, vol, sndDelay, loop)
  213.     end if
  214.     append(ListRolls, [rolls, snd, chnl])
  215.     set i to 1
  216.     repeat while i <= count(rolls)
  217.       set spriteNum to getAt(getAt(rolls, i), 1)
  218.       set rootName to getAt(getAt(rolls, i), 2)
  219.       set listFrames to getAt(getAt(rolls, i), 3)
  220.       set delay to getAt(getAt(rolls, i), 4)
  221.       startAnim(spriteNum, rootName, listFrames, delay, -1, 1)
  222.       set i to i + 1
  223.     end repeat
  224.   end if
  225. end
  226.  
  227. on cleanUpRolls
  228.   global ListRolls
  229.   set i to 1
  230.   set nbRolls to count(ListRolls)
  231.   repeat while i <= nbRolls
  232.     set ro to getAt(ListRolls, i)
  233.     set roAnim to getAt(ro, 1)
  234.     set snd to getAt(ro, 2)
  235.     set chnl to getAt(ro, 3)
  236.     set roTrigger to getAt(getAt(ro, 1), 1)
  237.     set spriteNum to getAt(roTrigger, 1)
  238.     if not rollOver(spriteNum) then
  239.       stopSoundSequence(snd, chnl)
  240.       set j to 1
  241.       set nbAnimSpr to count(roAnim)
  242.       repeat while j <= nbAnimSpr
  243.         set spriteNum to getAt(getAt(roAnim, j), 1)
  244.         stopAnim(spriteNum)
  245.         set j to j + 1
  246.       end repeat
  247.       deleteAt(ListRolls, i)
  248.       set nbRolls to nbRolls - 1
  249.     end if
  250.     set i to i + 1
  251.   end repeat
  252. end
  253.